package org.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class deleateDate {

    public static void deleteRecord(String url,String user,String password,int idToDelete) {
        try {
            // SQL语句：根据ID删除记录
            String sql = "DELETE FROM first_table WHERE Id = ?";

            // 获取连接
            Connection conn = DriverManager.getConnection(url, user, password);

            // 创建PreparedStatement对象
            PreparedStatement pstmt = conn.prepareStatement(sql);

            // 设置参数值
            pstmt.setInt(1, idToDelete);

            // 执行删除操作
            int rowsAffected = pstmt.executeUpdate();

            if (rowsAffected > 0) {
                System.out.println("Record with ID " + idToDelete + " has been deleted.");
            } else {
                System.out.println("No record found with ID " + idToDelete + ".");
            }

            // 关闭资源
            pstmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
